package com.atguigu.servlet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Arrays;

public class ForthServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
        String method = request.getMethod();
        System.out.println(method);
//      doGet(request,response);
//        String method = request.getMethod();//获取当前请求的请求方式
//        System.out.println("/获取当前请求的请求方式"+method);
    }


    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //post请求的方法
        request.setCharacterEncoding("UTF-8");
        //处理response响应客户端的相应问题
        response.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=UTF-8");
//        request.setCharacterEncoding("UTF-8");



        //1.获取请求参数
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        String[] hobbies = request.getParameterValues("hobby");

//        String hobby = request.getParameter("hobby");
        System.out.println("username="+username+",password="+password+",hobby="+ Arrays.toString(hobbies));

//        request.getRequestDispatcher("/success.html").forward(request,response);
//        PrintWriter writer = response.getWriter();
//        writer.write("<h1>success</h1>");
//        writer.print("你好");


//        响应浏览器
        request.getRequestDispatcher("/success.html").forward(request,response);
        PrintWriter writer = response.getWriter();
        writer.write("<h1>succes<h1>");
        writer.print("你好呀");
        //充定向
//        response.sendRedirect("success.html");
    }
}
